package com.alai04.android.scoreboard;

import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

public class ScoreDBHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME="scoredb";
	public static final String TABLE_SCORE="score";
	public static final String LORD="lord";
	public static final String DOUBLE="double";
	public static final String WINLOSE="winlose";
	public static final String TIMES="times";
	public static final String TABLE_NAMES="names";
	public static final String NAME="name";
	
	public ScoreDBHelper(Context context) {
		super(context, DATABASE_NAME, null, 1);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " + TABLE_SCORE + 
				" (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
				LORD + " INTEGER, " + DOUBLE + " INTEGER, " + 
				WINLOSE + " INTEGER, " + TIMES + " INTEGER);");
		db.execSQL("CREATE TABLE " + TABLE_NAMES + 
				" (" + NAME + " TEXT UNIQUE);");
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_SCORE);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAMES);
		onCreate(db);
	}
}